﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace EgneAktiviteter
{

    public sealed class WaitForInput<T> : NativeActivity<T>
    {
        public InArgument<string> BookmarkName { get; set; }

        protected override void Execute(NativeActivityContext context)
        {
            string bookmarkName = BookmarkName.Get(context);

            if (string.IsNullOrEmpty(bookmarkName))
            {
                bookmarkName = Guid.NewGuid().ToString();
            }

            context.CreateBookmark(bookmarkName, new BookmarkCallback(this.Continue));
        }

        void Continue(NativeActivityContext context, Bookmark bookmark, object obj)
        {
            if (obj != null)
            {
                Result.Set(context, (T)obj);
            }
        }

        protected override bool CanInduceIdle { get { return true; } }
    }
}
